<?php if(!IS_AJAX){?>
<include file="Public:header" />
<style>
    .sourceInput{ max-width:60px; margin-bottom:5px;}
    .sourcePanel{text-align: center;position: absolute;top: 30px;background: #fafafa;border: 1px solid #ddd;padding: 5px; display:none; z-index:3; min-width:110px;}
    .missionform {box-shadow: 0;}
    .formBox{ min-height:160px;}
    .checkoutform .form-inline{ position:relative; padding-left:10px;}
    .checkoutform .checkbox-inline{ padding-top:9px;}
    .checkoutform .form-inline .groupName{ min-width:80px; border-right:1px dotted; padding-right:5px;}
    .checkoutform .form-inline:nth-child(2n){ background-color:rgba(0,0,0,0.25); color:#fff;}
    .checkoutform .form-inline:nth-child(2n-1){ background-color:rgba(0,0,0,0.02);}
    .checkoutform .cover{ width:100%; height:100%; display:none; background:rgba(0,0,0,0.2); position:absolute; top:0; left:0;}
    .checkoutform .sourceEdit{outline: 1px dashed;outline-offset: -6px; transition:all 0.2s ease-in-out;}
    .checkoutform .sourceEdit:hover{ background:rgba(0,0,0,0.03); outline-style:dotted;}
</style>
<div class="row">
    <div class="col-sm-12">
        <div style="margin-top:-15px; ">
            <form action="<?php echo U('index');?>" id="ajaxlistboxform" class="affixelement" afftop="0" style="background:#fff; z-index:3; margin-bottom:15px;">
                <div class="panel" style="margin-bottom:0; padding:15px;">
                    <input type="hidden" name="state" value="all">
                    <input type="hidden" name="listcheck" value="0">
                    <div class="icheck">
                        <div class="input-group" style="width:300px;">
                            <input type="text" name="keywords" value="<?php echo $keywords; ?>"  placeholder="审批名称或姓名" class="form-control">
              <span class="input-group-btn">
              <button type="submit" class="btn btn-default"><i class="fa icon-search"></i></button>
              </span> </div>
                        <div>
                            <input class="form-control datepicker" id="starttime" name="starttime" readonly style="cursor:pointer; width:120px; display:inline;" value="<?php echo $starttime; ?>" placeholder="起始时间" type="text">
                            至
                            <input class="form-control datepicker" id="endtime" name="endtime" readonly style="cursor:pointer; width:120px; display:inline;" value="" placeholder="结束时间" type="text">
                            <select class="form-control" name="pagesize" style="display:inline;margin-right:15px; width:auto;" onchange="$('#ajaxlistboxform').submit()">
                                <option value="10"

                                <eq name="pagesize" value="10">selected="selected"</eq>
                                >每页10条
                                </option>
                                <option value="25"
                                <eq name="pagesize" value="25">selected="selected"</eq>
                                >每页25条
                                </option>
                                <option value="50"
                                <eq name="pagesize" value="50">selected="selected"</eq>
                                >每页50条
                                </option>
                                <option value="100"
                                <eq name="pagesize" value="100">selected="selected"</eq>
                                >每页100条
                                </option>
                            </select>
                            <!--   <a href="##" id="ajaxlistboxbob">批量操作</a>-->
                        </div>
                        <div id="ajaxlistboxboc" style="display:none;"> <a href="##" class="btn btn-info" id="ajaxlistboxsa"> 全选 </a> <a href="##" class="btn btn-info" id="ajaxlistboxca"> 全不选 </a> <a href="##" class="btn btn-info" id="ajaxlistboxsar"> 反选 </a> <a rel="{:U('pass')}" href="##" class="btn btn-success"> 通过 </a> </div>

                        <!-- 右边 -->
                        <div class="pull-left" style="line-height:34px;" id="missioncountbox"> </div>
                        <span class="pull-right" id="listcheck"><i class="fa icon-th" style="cursor:pointer"></i>　<i class="fa icon-list" style="cursor:pointer"></i></span>
                        <!-- 右边结束 -->
                        <div style="float:none; clear:both;"> </div>
                    </div>
                </div>
            </form>
        </div>
        <form id="missioncountboxform" action="{:U('missioncount')}">
        </form>
    </div>
    <div class="col-sm-12">
        <div class="panel">
            <div class="panel-heading"> <span class="pagetitle">审批管理</span> </div>
            <div class="panel-body">
                <div id="masonrybox1"></div>
                <div  id="ajaxlistbox" class="hidden">
                    <?php    }?>
                    <?php if(IS_AJAX){?>
                    <!-- 数据主体 -->
                    <if condition="$listcheck eq 1 ">
                        <else />
                        <volist name="list" id="vo">
                            <!--添加界面引导 BY zmx-->
                            <div class="box col-sm-6 col-lg-4 missionform" style="" <eq name="key" value="0">data-position="right" data-intro="这里处理审批文件的地方，每一个就是一个待审批的文案，里面展示了该审批的内容，你可以快速的预览并且做出判断，之后通过下面的【通过】【驳回】按钮快速完成审批工作，系统后台会将结果通知到申请人"</eq>>
                            <div class="panel panel-mission" style="margin:5px 0; position:relative; box-shadow: 2px 2px 5px #aaa; border-radius:0; border:1px solid #ccc; padding:15px;">
                                <!--{$html.$i}-->
                                <div class="BatchOperation BatchOperationBtn">
                                    <input class="checkbox" type="checkbox" name="id[]" value="{$vo.id}">
                                    <i class="fa icon-check"></i>
                                    <div class="fabg"> </div>
                                </div>
                                <h4 class="panel-heading">{$vo.title} {$vo.state}</h4>
                                <div class="formBox <eq name="vo['state']" value="0"> a</eq><eq name="vo['state']" value="3">p</eq>" id="formBox-{$vo.id}" > {$vo['formtemplate']} </div>
                            <h4 class="panel-heading">审批意见</h4>
                            <p>由【{$vo.approvername}】审批</p>
                            <div class="schedulebox" id="schedulebox-{$vo.id}">
                                <notempty name="vo['schedule']">
                                    <volist name="vo['schedule']" id="s">
                                        <p>意见：
                                            <notempty name="s['comment']">{$s.comment}
                                                <else/>
                                                无</notempty>
                                            <eq name="s['status']" value="0"> 　<span class="label label-danger">驳回</span> </eq>
                                            <eq name="s['status']" value="1"> 　<span class="label label-success">通过</span> </eq>
                                            <gt name="s['sendParent']" value="0"><span class="label label-info">已递交上级</span></gt>
                                        </p>

                                        <gt name="s['ticketnum']" value="0">
                                            <p>获得<span style="color:#f60;">{$s.ticketnum}</span>张奖票</p>
                                        </gt>
                                        <table class="table table-bordered" style="border:1px solid #ccc; margin-bottom:10px;">
                                            <volist name="s['integrals']" id="rvo">
                                                <tr>
                                                    <td>{$rvo.name} 【获得{$InteTypeList[$rvo['type']]} <span style="color:#f60; font-weight:bold; font-family:Cambria, 'Hoefler Text', 'Liberation Serif', Times, 'Times New Roman', serif;">{$rvo.num}</span>】</td>
                                                </tr>
                                            </volist>
                                        </table>
                                        <p></p>
                                        <p><span class="pull-left">{:date('Y-m-d H:i:s', $s['datatime'])}</span><span class="pull-right">审批人：{$s.membername}</span>
                                        <div class="clearfix"> </div>
                                        </p>
                                        <hr>
                                    </volist>
                                    <else/>
                                    <div style="padding:5px; text-align:center;"> 暂无审批记录 </div>
                                </notempty>
                            </div>
                            <div id="schedulebox-{$vo.id}pages"> </div>
                            <div id="passform-{$vo.id}-integral">
                                <if condition="$vo['integral']">
                                    <table class="table table-bordered" style="border:1px solid #ccc; margin-bottom:10px;">
                                        <thead bgcolor="#F7F7F7">
                                        <tr>
                                            <th width="80">姓名</th>
                                            <volist name="vo['integral']" id="rvo">
                                                <volist name="rvo['integral']" id="ivo">
                                                    <th>{$InteTypeList[$key]}</th>
                                                </volist>
                                            </volist>
                                        </tr>
                                        </thead>
                                        <volist name="vo['integral']" id="rvo">
                                            <assign name="midk" value="$key" />
                                            <tr>
                                                <td>{$rvo.name}</td><volist name="rvo['integral']" id="ivo">
                                                <td>
                                                    <input class="form-control" type="hidden" name="integralmember_id[]" value="{$midk}">
                                                    <if condition="$giveintegral">
                                                        <input class="form-control" type="number" name="integralnum[]" value="{$ivo}">
                                                        <else/>
                                                        {$ivo}
                                                        <input class="form-control" type="hidden" name="integralnum[]" value="{$ivo}">
                                                    </if>
                                                    <input class="form-control" type="hidden" name="integraltype[]" value="{$key}">
                                                </td> </volist>
                                            </tr>
                                        </volist>
                                    </table>
                                </if>
                                <if condition="$userInfo['tiketnum'] egt 0">
                                    <p>发奖票： <input class="form-control" type="number" name="ticket" value="0" min="0" style="display:inline-block; width:60px;"> 张</p>
                                </if>
                            </div>
                            <form id="schedulebox-{$vo.id}form" action="{:U('schedule', array('id' => $vo['id']))}">
                            </form>
                            <div class="panel" style="border:1px solid #ccc; margin-bottom:0;">
                                <!--添加界面引导 BY zmx-->
                                <form id="passform-{$vo.id}" action="{:U('pass')}">
                                    <div id="passform-{$vo.id}-integralbox" class="hidden">
                                    </div>
                                    <textarea class="form-control input-lg p-text-area" name="comment" rows="2" placeholder="填写意见">{$vo.myschedule.comment}</textarea>
                                    <input type="hidden" value="0" name="status">
                                    <input type="hidden" name="mission_id" value="{$vo['id']}">
                                </form>
                                <footer class="panel-footer" style="padding:5px;">
                                    <button onClick="passform{$vo.id}(1);" class="btn btn-post btn-sm pull-right" >通过</button>
                                    <button style="margin-right:5px;" class="btn btn-default btn-sm pull-right" onClick="passform{$vo.id}(0);" >驳回</button>
                                    <ul class="nav nav-pills p-option">
                                        <li style="line-height:30px;"> 申请人：{$vo['proposername']} </li>
                                    </ul>
                                </footer>
                                <script>
                                    function passform{$vo.id}(status){
                                        $('#passform-{$vo.id}').find('input[name="status"]').val(status);

                                        $('#passform-{$vo.id}-integral').find('input[type="number"]').each(function(index, element) {
                                            //alert();
                                            $(this).attr('value', $(this).val());
                                        });

                                        $('#passform-{$vo.id}-integralbox').html($('#passform-{$vo.id}-integral').html());
                                        //return false;

                                        //$('#passform-{$vo.id}').find('input[name="ticket"]').val($('#passform-{$vo.id}-integral').find('input[name="ticket"]').val());
                                        var data = $('#passform-{$vo.id}').serialize();
                                        $.ajax({
                                            url:$('#passform-{$vo.id}').attr('action'),
                                            data:data,
                                            type:'POST',
                                            dataType:"json",
                                            success: function(ret){
                                                if(ret.status == 1){
                                                    //成功了
                                                    //document.getElementById('passform-{$vo.id}').reset();
                                                    $('#schedulebox-{$vo.id}form').trigger('submit');
                                                    if(ret.state == 3){
                                                        $('#formBox-{$vo.id}').css('background-size','100% auto');
                                                        $('#formBox-{$vo.id}').removeClass('a');
                                                        $('#formBox-{$vo.id}').addClass('p');
                                                    }
                                                    if(ret.state == 0){
                                                        $('#formBox-{$vo.id}').css('background-size','100% auto');
                                                        $('#formBox-{$vo.id}').removeClass('p');
                                                        $('#formBox-{$vo.id}').addClass('a');
                                                    }
                                                    setTimeout(function(){
                                                        $('#formBox-{$vo.id}').css('background-size','50% auto');

                                                        //更新单个记录，这样不会造成页面有大变化
                                                        $.get('{:U('getOne')}', {
                                                            id:{$vo.id}
                                                    }, function(data){
                                                            //alert(data.tbody);
                                                        }, 'json');
                                                        updatemasonry();
                                                        $('#missioncountboxform').submit();
                                                        $('#ajaxlistboxform').submit();
                                                    },30);
                                                }
                                                //如果没有表格则弹窗
                                                if(ret.status == 2){
                                                    _openWindow('{:U('choiceForm') }&'+data, 500, '选择表格', '确认', function(){ passform{$vo.id}(status)}, '');
                                                }
                                            }
                                        });
                                    }
                                </script>
                            </div>
                </div>
            </div>
            <!-- 数据主体结束 -->
            </volist>
            </if>
            <?php }?>
            <?php if(!IS_AJAX){?>
        </div>
        <div id="ajaxlistboxpages" class="pagesBox text-center"> <?php echo $pages;?> </div>
    </div>
</div>
</div>
</div>
<include file="Public:script" />
<script src="__PUBLIC__/Js/jquery.masonry.min.js"></script>
<script>
    $('#listcheck i').each(function(){
        $(this).click(function(){
            $("#ajaxlistboxform input[name='listcheck']").val($(this).index());
            $('#ajaxlistboxform').submit();
        });
    });
    $('#missioncountbox').ajaxlist();
    $('.icheck input').change(function(){
        $('#ajaxlistboxform').submit();
    });
    $.cookie('loadIndexUrl', window.location.href, {path:'/'});
    function mission_send(id,e){
        if(!confirm('确定递交吗？')){
            return false;
        }
        hideLayer();
        $.post('{:U('send')}', {id:id}, function(data){
            if(data.status == 1){
                $('#ajaxlistboxform').submit();
                //updateList();
            }else{
                alert(data.info);
            }
        }, 'json');
    }
    function mission_cancel(id,e){
        if(!confirm('确定取消吗？')){
            return false;
        }
        hideLayer();
        $.post('{:U('cancel')}', {id:id}, function(data){
            if(data.status == 1){
                $('#ajaxlistboxform').submit();
                //updateList();
            }else{
                alert(data.info);
            }
        }, 'json');
    }
    /*var sct = $(window).scrollTop();
     var affixtop = $('.affixelement.affix-top').offset().top;
     $(window).scroll(function(e) {
     if(sct > $(this).scrollTop()){
     //alert('上滚');
     $('.header-section').animate({top:'0px'},{queue:false});
     $('.sticky-header .main-content').removeClass('hiddentop');
     $('.affixelement.affix-top').animate({top:affxtop+'px',speed:50});
     }else{
     //alert('下滚');
     $('.sticky-header .main-content').addClass('hiddentop');
     $('.header-section').animate({top:'-80px'},{queue:false,speed:50});
     $('.affixelement.affix-top').animate({top:'0'});
     }
     sct = $(this).scrollTop();
     });*/
    //有关于页面的一系列事件
    function sourceInput(e){
        //$(this).find(".sourceInput").attr("type",'number')
        if($(this).find(".sourceInput").css('display')!='block'){
            $(".sourcePanel").hide();
        }
        $(this).find(".sourcePanel").show();
        $(this).find(".hidden").removeClass("hidden");
    }
    $("#masonrybox1").on("click",".checkbox-inline",sourceInput);
    //获得焦点的时候显示面板
    $("#masonrybox1").on("focusin",".single-row .sourcePanel",function(){
        var self=$(this);
        //window.setTimeout(function(){
        window.clearTimeout(window.time);
        self.show();
        //},10);
    });
    //失去焦点的时候隐藏面板
    $("#masonrybox1").on("blur",".single-row",function(){
        //$(this).find(".sourceInput").attr("type",'hidden')
        var self=$(this);
        window.time=setTimeout(function(){
            self.find(".sourcePanel").hide();
            //计算总分数
            var inte={};
            var num=0;
            self.parents('.panel-mission').find('.sourceInput').each(function(index,element){
                if(!($(this).attr('data-type') in inte)){
                    inte[$(this).attr('data-type')]=0
                }
                console.log($(this).attr('data-type'));
                if($(this).val()==''){
                    num=$(this).attr('min')-0;
                }else{
                    num=$(this).val()-0;
                    num=num<$(this).attr('min')-0?$(this).attr('min')-0:num;
                    num=num>$(this).attr('max')-0?$(this).attr('max')-0:num;
                }
                console.log(num);
                inte[$(this).attr('data-type')]=inte[$(this).attr('data-type')]+num;
            });
            //加分
            $.each(inte,function(index,element){
                self.parents('.panel-mission').find("table input[value='"+index+"']").prev().val(element);
            });
            console.log(inte);
        },100);
    });
    function setstate(state){
        reloadmasonry();
        $('#ajaxlistboxform').find('input[name="state"]').val(state);
        $('#ajaxlistboxform').submit();
    }
    function reloadmasonry(){
        $('#masonrybox1').masonry('destroy').empty();
        $('#masonrybox1').masonry({itemSelector: '.box',columnWidth: 0,isAnimated : true});
    }
    function updatemasonry(){
        if($('#masonrybox1').children().length > 0){
            $('#masonrybox1').masonry('destroy').empty();
        }
        $('#masonrybox1').masonry({itemSelector: '.box',columnWidth: 0,isAnimated : true});
    }
    updatemasonry();
    $('#ajaxlistbox').ajaxlist({append:true,
        success:function(obj){
            $('.schedulebox').ajaxlist({autoload:false});
            //当数据成功获取的时候将表单转化为纯文
            $('.formBox .form-control').each(function(index, element) {
                var val = $(this).val();
                $(this).replaceWith('<span style="color:#f60;">'+val+'</span>');
            });
            //当数据成功获取的时候将选择项转化为纯文本
            $('.formBox .single-row').each(function(index, element) {
                $(this).find('*').unbind();
                if($(this).find(".checked").length==0){
                    $(this).parent().remove();
                }else{
                    var input=$(this).find(".checked").removeAttr("class").parent().next();
                    if(isNaN(Number(input.val()))){
                        //input.attr("type","number").addClass('form-control').css('max-width','110px');
                    }
                }
                //显示出可点击的框框
                if($(this).find('.sourcePanel').length){
                    $(this).parent().addClass('sourceEdit');
                }
            });
            /*$('.formBox .checkbox').each(function(index, element) {
             if($(this).find("input")[0].checked){
             $(".formBox hr").remove();
             var val=$(this).find("input").next().text();
             $(this).parent().replaceWith('<span style="color:#f60;">'+val+'</span>');
             }else{
             $(this).parent().remove();
             };
             });*/
            $(".sourcePanel label").each(function(index, element) {
                <volist name="integraltypelist" id="vo">
                        $(this).text($(this).text().replace('{$vo.typename}','{$vo.remark}'));
                </volist>
            });
            var html = $('#ajaxlistbox').children();
            $newElems = html.appendTo('#masonrybox1');
            $newElems.imagesLoaded(function(){
                $('#masonrybox1').masonry( 'appended', $newElems, true);$(window).trigger('resize');
            });
        }
    });
    $('.datepicker').datepicker({ dateFormat: 'yy-mm-dd' });
</script>
<style>
    .hiddentop{padding-top:0 !important;}
    .formBox.a{background:url(__PUBLIC__/a.png) no-repeat center center; background-size:50% auto;}.formBox.p{background:url(__PUBLIC__/p.png) no-repeat center center; background-size:50% auto;}
</style>
</body></html><?php }?>